<template>
  <div>
    <div style="display: flex;font-weight: bold;color: #000000;justify-content: center;font-size: 29px;padding: 20px">
      重大研发专项计划需求征集表
    </div>
    <t-form labelAlign="top" ref="form" :data="formData"  class="step-form table-form"
            labelWidth="140px">
      <t-row>
        <t-col :span="2" class="title">基本信息</t-col>
        <t-col :span="10" style="display:block;padding: 0 !important; border: 0">
          <t-row>
            <t-col :span="2" class="sub-title text-center"><span class="require">*</span>研究方向</t-col>
            <t-col :span="10">
              <t-form-item name="researchDirection">
                {{ formData.researchDirection }}
              </t-form-item>
            </t-col>
          </t-row>
          <t-row>
            <t-col :span="2" class="sub-title text-center"><span class="require">*</span>研发需求
            </t-col>
            <t-col :span="10">
              <t-form-item  name="projectName">
                {{ formData.projectName }}
              </t-form-item>
            </t-col>
          </t-row>
          <t-row>
            <t-col :span="2" class="sub-title text-center"><span class="require">*</span>提出人（团队）</t-col>
            <t-col :span="10">
              <t-form-item  name="introducer">
                {{ formData.introducer }}
              </t-form-item>
            </t-col>
          </t-row>
          <t-row>
            <t-col :span="2" class="sub-title text-center"><span class="require">*</span>所在单位</t-col>
            <t-col :span="10">
              <t-form-item  name="deptName">
                {{ formData.deptName }}
              </t-form-item>
            </t-col>
          </t-row>
          <t-row>
            <t-col :span="2" class="sub-title text-center"><span class="require">*</span>联系电话</t-col>
            <t-col :span="10">
              <t-form-item  name="phone">
                {{ formData.phone }}
              </t-form-item>
            </t-col>
          </t-row>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title">相关附件</t-col>
        <t-col :span="10">
          <t-table size="small" row-key="id" :columns="projectFileColumns" :data="projectFileData">
            <template #id="{row, rowIndex}">
              {{ rowIndex+1 }}
            </template>
            <template #c1="{row}">
              <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1 }}</a>
              <div v-else>{{ row.c1 }}</div>
            </template>
            <template  #op="{row}">
              <div v-for="(item,index) in row.fileLists" :key="index">
                <a class="t-button-link" target="_blank" :href="item.url" >
                  {{item.name}}
                </a>
              </div>
            </template>
          </t-table>
        </t-col>
      </t-row>
    </t-form>
  </div>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import {getFiles} from "@/api/common";

export default {
  name: "special-plan-detail",
  props: {
    objId: [String, Number],
    reviewOpen: {
      type: Boolean,
      default: false
    },
  },
  data(){
    return {
      file_domain: VITE_FILE_DOMAIN,
      formData: {
        id: null,
        researchDirection: '',
        projectName: '',
        introducer: '',
        deptName: '',
        phone: '',
      },
      projectFileData: [
        {
          id: 1,
          c1: "需求征集表",
          c2: "是",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectXQZJB",
          require: true,
        },
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },

        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "附件列表",
          align: "left",
        },
      ],
    }
  },
  watch: {
    objId: {
      immediate: true,
      handler(val) {
        if (val) {
          this.getObj(val);
        }
      }
    },
  },
  methods:{
    getObj() {
      this.$api.ggxq.specialPlan.get(this.objId).then(response => {
        if (response.data.createUserId === Number(this.$store.state.user.userId)) {
          this.isMyProject = true;
        }
        Object.assign(this.formData, response.data);
        getFiles(response.data.id).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          this.projectFileData.forEach((val, index) => {
            this.projectFileData[index].fileLists = files[val.moduleKey] || [];
            this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
          })
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    }
  }
}
</script>

<style scoped>

</style>
